package com.xintai.system.controller;

import java.util.List;

import com.xintai.utils.StaticString;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xintai.common.annotation.Log;
import com.xintai.common.core.controller.BaseController;
import com.xintai.common.core.domain.AjaxResult;
import com.xintai.common.enums.BusinessType;
import com.xintai.system.domain.ErpCangku;
import com.xintai.system.service.IErpCangkuService;
import com.xintai.common.utils.poi.ExcelUtil;
import com.xintai.common.core.page.TableDataInfo;

/**
 * ERP仓库Controller
 * 
 * @author xintai
 * @date 2020-12-28
 */
@RestController
@RequestMapping("/system/cangku")
public class ErpCangkuController extends BaseController
{
    @Autowired
    private IErpCangkuService erpCangkuService;

    /**
     * 查询ERP仓库列表
     */
    @PreAuthorize("@ss.hasPermi('system:cangku:list')")
    @GetMapping("/list")
    public TableDataInfo list(ErpCangku erpCangku)
    {
        startPage();
        List<ErpCangku> list = erpCangkuService.selectErpCangkuList(erpCangku);
        return getDataTable(list);
    }

    /**
     * 导出ERP仓库列表
     */
    @PreAuthorize("@ss.hasPermi('system:cangku:export')")
    @Log(title = "ERP仓库", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ErpCangku erpCangku)
    {
        System.out.println(erpCangku);
        List<ErpCangku> list = erpCangkuService.selectErpCangkuList(erpCangku);
        ExcelUtil<ErpCangku> util = new ExcelUtil<ErpCangku>(ErpCangku.class);
        return util.exportExcel(list, "cangku");
    }

    /**
     * 获取ERP仓库详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:cangku:query')")
    @GetMapping(value = "/{cangkuId}")
    public AjaxResult getInfo(@PathVariable("cangkuId") Integer cangkuId)
    {
        return AjaxResult.success(erpCangkuService.selectErpCangkuById(cangkuId));
    }

    /**
     * 新增ERP仓库
     */
    @PreAuthorize("@ss.hasPermi('system:cangku:add')")
    @Log(title = "ERP仓库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpCangku erpCangku)
    {
        if (erpCangkuService.verifyErpCangku(erpCangku))
            return AjaxResult.error(StaticString.NameRepeat(erpCangku.getCangkuName()));
        return toAjax(erpCangkuService.insertErpCangku(erpCangku));
    }

    /**
     * 修改ERP仓库
     */
    @PreAuthorize("@ss.hasPermi('system:cangku:edit')")
    @Log(title = "ERP仓库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpCangku erpCangku)
    {
        if (erpCangkuService.verifyErpCangku(erpCangku))
            return AjaxResult.error(StaticString.NameRepeat(erpCangku.getCangkuName()));
        return toAjax(erpCangkuService.updateErpCangku(erpCangku));
    }

    /**
     * 删除ERP仓库
     */
    @PreAuthorize("@ss.hasPermi('system:cangku:remove')")
    @Log(title = "ERP仓库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cangkuIds}")
    public AjaxResult remove(@PathVariable Integer[] cangkuIds)
    {
        return toAjax(erpCangkuService.deleteErpCangkuByIds(cangkuIds));
    }
}
